<template>
	<view class="template-classify">
		<tn-nav-bar fixed :isBack="false" :bottomShadow="false">文案中心</tn-nav-bar>
		<scroll-view :style="{paddingTop: vuex_custom_bar_height + 'px'}" class="container"
		 scrollWithAnimation="true" scroll-y="true" @scrolltolower="scroll_bottom">
			<view class="view_sousuo" @tap="tn(`/pages/Copywritingsearch/index`)">
				<view class="view_sousuo_input">
					<image src="../../static/resource/icon_sousuo.png"></image>
					<text>搜索文案</text>
				</view>
			</view>
			<view class="lunbotu_view">
				<swiper class='top_lunbo' indicator-dots='false' autoplay='true' interval='5000' duration='1000'>
					<block>
						<swiper-item>
							<image
								src="https://haibao-1302875111.cos.ap-shanghai.myqcloud.com/images/5/2023/03/b2pT6pX6szZ77ur7HPRqhjSE16B7pr.jpg"
								class="slide-image" />
						</swiper-item>
					</block>
				</swiper>
			</view>
			<view class="select_back_view" v-if="show_all_fenlei==1"></view>
			<view class="select_view">
				<view class="select_title">
					<!-- 	<view class="select_title_item" :class="cur_select_index==3?'select_title_item_on':''" @tap="select"
						data-index="3">
						最新</view> -->
					<view class="select_title_item" :class="cur_select_index==index ?'select_title_item_on':''"
						v-for="(item,index) in wenan_fenleiinfo" @tap="select" :data-index="index" :data-id="index">
						{{item.name}}
					</view>
				</view>
				<view class="select_fenlei_body" v-if="show_all_fenlei==1">
					<view class="select_fenlei_body_top">
						<view class="select_fenlei_item" :class="fenlei_selected[index]==1?'select_fenlei_item_on':''"
							v-for="(item,index) in wenan_fenleiinfo" @tap="select_fenlei" :data-index="index">
							{{item.name}}
						</view>
					</view>
					<view class="select_fenlei_btns">
						<view class="select_fenlei_btns_left" @tap="clear_select">清除</view>
						<view class="select_fenlei_btns_right" @tap="wancheng">完成</view>
					</view>
				</view>
			</view>
			 <tn-empty mode="list" text="暂无"  v-if="wenan_info.length == 0"></tn-empty>
			<view class="wenan_view" v-if="wenan_info.length > 0">
				<view class="wenan_view-flex" v-for="(item,index) in wenan_info">
					<view class="wenan_item">
						<image class="wenan_tx" :src="item.tx==''? setting.tx:item.tx"></image>
						<view class="wenan_right">
							<view class="wenan_right_top">
								<view class="wenan_right_top_left">
									<view class="wenan_nickname">{{item.nickname==''?setting.nickname:item.nickname}}
									</view>
									<view class="wenan_date">{{item.create_time}}</view>
								</view>
								<view class="wenan_right_top_right" @click="tn(`/pages/Posterproject/richtext/index`)">
									<image src="../../static/resource/icon_mianze_sm.png"></image>
									<view>免责声明</view>
								</view>
							</view>
							<view class="wenan_right_content">{{item.content}}</view>
							<view class="img_view" v-if="item.kind==0">
								<image mode="widthFix" :src="item.hbicon" :data-url="item.hbicon" @tap="preview_img">
								</image>
							</view>
							<view class="pics_view" v-else-if="item.kind==1">
								<image
									:class="item.pics.length == 1 ? 'image1':(item.pics.length == 2 ? 'image2':'image3')"
									mode="widthFix" :src="itemName" v-for="(item,index) in item.pics"
									:data-urlimg="itemName" :data-url="item.pics" @tap="preview_img">
								</image>
							</view>
							<view class="pics_view" v-else>
								<video :customCache="false" id="video-intro" :src="item.video" :autoplay="false">
								</video>
							</view>
							<view class="wenan_btns">
								<view class="btns_item" @tap="wanna_down(index)">
									<image src="../../static/resource/xia.png"></image>
									<view>下载复制</view>
								</view>
								<view class="btns_item" @click="tn(`/pages/Posterproject/poster/index?id=${item.hbid}`)">
									<image src="../../static/resource/she.png"></image>
									<view>制作海报</view>
								</view>
								<view class="btns_item">
									<image src="../../static/resource/xian.png"></image>
									<view>一键分享</view>
									<button open-type="share" class="btn_share" style="opacity: 0;"></button>
								</view>
							</view>
						</view>
					</view>
					<view class="hr"></view>
				</view>
			</view>
		</scroll-view>
		<view class='jieguo_view' v-if="wenan_show_status== true">
			<view class="jieguo_content">
				<image src="../../static/resource/bg_wenan_bcss.png" class="jieguo_content_bg"></image>
				<view class="jieguo_content_btn_close" @tap="jieguo_content_close"></view>
				<view>
					<view class="jieguo_tishi_1">可使用免费下载次数1次</view>
					<view class="jieguo_tishi_2">分享给好友可获得更多下载次数</view>
					<view class="btns_view">
						<button open-type="share" class="btns_view_left">分享</button>
						<view class="btns_view_right" @tap="download_zuopin">下载</view>
					</view>
				</view>
			</view>
		</view>
		<tabbar :currentIndex="2"></tabbar>
	</view>
</template>

<script>
	import tabbar from '@/components/tabbar/index.vue'
	import {
		catelist,
		copy_writinglist,
		download
	} from '@/api/poster/index.js'
	export default {
		components: {
			tabbar
		},
		data() {
			return {
				cur_select_index: 0,
				fenlei_selected: [],
				fenlei_selected_num: 0,
				fenlei_selected_cache: [],
				setting: null,
				uid: 0,
				wenan_lbt: [],
				//下载图片临时参数
				cur_down_wenan: null,
				wenan_show_status: false,
				wenan_user_info: null,
				cur_show_wenan: null,
				wenan_fenleiinfo: [],
				wenan_info: [],
				show_all_fenlei: 0,
				rpx_to_px: 1,
				fenlei_guding: 0,
				//下载图片临时参数
				cur_down_index: 0,
				pics_down: [],
				downing: 0,
				sys_ios: 1, //1代表是苹果系统
				jili: null,
				videoAd: null,
				per_page_states:false,
				page:1
			}
		},
		onLoad() {
			this.getcatelist()
		},
		onShow() {

		},
		methods: {
			scroll_bottom(){
				if(this.per_page_states == false){
					this.page = this.page + 1
					this.getcopy_writinglist()
				}
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
			/**
			 * 下载作品
			 */
			download_zuopin: function(e) {
				var that = this;
				uni.getSetting({
					success(res) {
						if (res.authSetting['scope.writePhotosAlbum'] == false) {
							uni.openSetting({
								success(res) {
									if (res.authSetting['scope.writePhotosAlbum'] == true) {
										that._download_zuopin();
									}
								}
							})
						} else if (res.authSetting['scope.writePhotosAlbum'] == undefined) {
							uni.authorize({
								scope: 'scope.writePhotosAlbum',
								success(res) {
									that._download_zuopin();
								}
							})

						} else {
							that._download_zuopin();
						}
					}
				})
			},
			_download_zuopin: function() {
				var that = this;
				uni.showLoading({
					title: '保存中'
				});
				uni.getImageInfo({
					src: this.cur_down_wenan.hbicon,
					success(res) {
						that.wenan_show_status = false
						uni.saveImageToPhotosAlbum({
							filePath: res.path,
							success(res) {
								uni.hideLoading();
								uni.showToast({
									title: '保存成功',
								})
							}
						})
					}
				})
			},
			wanna_down: function(e) {
				const AccessToken = uni.getStorageSync('AccessToken')
				if (!AccessToken) {
					uni.showToast({
						icon:'none',
						title: '请登录',
						duration: 2000
					});
					return
				}
				this.cur_down_wenan = this.wenan_info[e];
				var that = this;
				uni.getSetting({
					success(res) {
						console.log(res.authSetting['scope.writePhotosAlbum']);
						if (res.authSetting['scope.writePhotosAlbum'] == false) {
							uni.openSetting({
								success(res) {
									if (res.authSetting['scope.writePhotosAlbum'] == true) {
										that.wenan_show_status = true
									}
								}
							})
						} else if (res.authSetting['scope.writePhotosAlbum'] == undefined) {
							uni.authorize({
								scope: 'scope.writePhotosAlbum',
								success(res) {
									that.wenan_show_status = true
								}
							})
						} else {
							that.wenan_show_status = true
						}
					}
				})
			},
			jieguo_content_close(){
				this.wenan_show_status = false
			},
			getcatelist() {
				catelist().then(res => {
					this.wenan_fenleiinfo = res.data.list
					this.getcopy_writinglist()
				})
			},
			getcopy_writinglist() {
				copy_writinglist({
					category_id: this.wenan_fenleiinfo[this.cur_select_index].id,
					page:this.page
				}).then(res => {
					this.wenan_info.push(...res.data.list.data)
					if(res.data.list.per_page > res.data.list.data.length){
						this.per_page_states = true
					}
				})
			},
			select: function(e) {
				const AccessToken = uni.getStorageSync('AccessToken')
				if (!AccessToken) {
					uni.showToast({
						icon:'none',
						title: '请登录',
						duration: 2000
					});
					return
				}
				for (var i = 0; i < this.fenlei_selected.length; i++) {
					this.fenlei_selected[i] = 0;
				}
				var index = e.currentTarget.dataset.index;
				if (index == this.cur_select_index) {
					return;
				}
				this.wenan_info = []
				this.page = 1
				this.per_page_states = false
				this.cur_select_index = index
				this.getcopy_writinglist()
			},
		}
	}
</script>

<style lang="scss" scoped>
	/deep/ .tn-empty-class{
		margin-top: 140rpx;
	}
	.jieguo_view {
		width: 750rpx;
		height: 100%;
		position: fixed;
		left: 0rpx;
		top: 0rpx;
		background-color: rgba(0, 0, 0, 0.3);
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		z-index: 999;
	}

	.jieguo_content {
		width: 504rpx;
		height: 578rpx;
		position: relative;
	}

	.jieguo_content_bg {
		width: 504rpx;
		height: 578rpx;
		position: absolute;
		left: 0rpx;
		top: 0rpx;
	}

	.jieguo_content_btn_close {
		width: 80rpx;
		height: 80rpx;
		position: absolute;
		top: 0rpx;
		right: 0rpx;
	}

	.jieguo_tishi {
		font-size: 28rpx;
		font-family: Adobe Heiti Std;
		font-weight: normal;
		color: rgba(51, 51, 51, 1);
		position: absolute;
		left: 49rpx;
		top: 114rpx;
	}

	.jieguo_tishi_1 {
		width: 504rpx;
		position: absolute;
		left: 0rpx;
		top: 295rpx;
		text-align: center;
		height: 34rpx;
		line-height: 34rpx;
		font-size: 36rpx;
		font-family: SimHei;
		font-weight: 400;
		color: rgba(68, 68, 68, 1);
	}

	.jieguo_tishi_2 {
		width: 484rpx;
		position: absolute;
		left: 10rpx;
		top: 354rpx;
		text-align: center;
		height: 31rpx;
		font-size: 32rpx;
		font-family: SimHei;
		font-weight: 400;
		color: rgba(56, 56, 56, 1);
	}

	.btns_view {
		width: 504rpx;
		position: absolute;
		left: 0rpx;
		top: 458rpx;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
	}

	.btns_view_left {
		width: 186rpx;
		height: 76rpx;
		line-height: 76rpx;
		text-align: center;
		border: 2rpx solid rgba(201, 208, 218, 1);
		border-radius: 10rpx;
		margin: 0 40rpx 0 0;
		font-size: 32rpx;
		font-family: SimHei;
		font-weight: 400;
		color: rgba(57, 57, 57, 1);
	}

	.btns_view_right {
		width: 190rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		background: rgba(255, 221, 2, 1);
		border-radius: 10rpx;
	}

	.container {
		width: 750rpx;
		height: 100%;
		position: absolute;
		left: 0rpx;
		right: 0rpx;
		margin-bottom: 50rpx;
	}

	.view_sousuo {
		width: 700rpx;
		height: 64rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		position: relative;
		margin: 15rpx auto 0 auto;
	}

	.view_sousuo_icon {
		width: 80rpx;
		height: 52rpx;
	}

	.view_sousuo_input {
		width: 700rpx;
		height: 64rpx;
		background: rgba(240, 239, 239, 0.4);
		border-radius: 10rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
	}

	.view_sousuo_input image {
		width: 30rpx;
		height: 30rpx;
		margin-right: 21rpx;
	}

	.view_sousuo_input text {
		font-size: 28rpx;
		font-family: SimHei;
		font-weight: 400;
		color: rgba(114, 114, 114, 1);
	}

	.goods_fenlei {
		width: 700rpx;
		height: 44rpx;
		overflow: hidden;
		white-space: nowrap;
		position: relative;
		display: block;
		margin-left: 15rpx;
		margin-top: 35rpx;
	}

	.goods_fenlei text {
		margin-left: 30rpx;
		height: 26rpx;
		line-height: 26rpx;
		display: inline-block;
	}

	.goods_fenlei_item {
		font-size: 26rpx;
	}

	.goods_fenlei_item_active {
		font-size: 28rpx;
		border-bottom: 6rpx solid #FFDD02;
		box-sizing: border-box;
	}

	.tuijian_content {
		width: 750rpx;
		position: relative;
		left: 0rpx;
		margin-top: 30rpx;
	}

	.lunbotu_view {
		width: 700rpx;
		height: 240rpx;
		/* background-color: rgb(243, 216, 168); */
		position: relative;
		margin: 0 auto;
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		margin-top: 20rpx;
	}

	.top_lunbo {
		width: 700rpx;
		height: 230rpx;
		border-radius: 10rpx;
	}

	.top_lunbo image {
		width: 700rpx;
		height: 230rpx;
		border-radius: 10rpx;
	}

	.wenan_view {
		width: 700rpx;
		margin: 0 auto;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding-bottom: 110rpx;
	}

	.wenan_view-flex {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.wenan_item {
		width: 700rpx;
		position: relative;
		padding-top: 30rpx;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: flex-start;
	}

	.wenan_view-flex .hr {
		width: 100vw;
		border: 1rpx solid rgba(240, 240, 240, 0.5);
		margin: 10rpx 0;
	}

	.wenan_tx {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		margin-right: 20rpx;
	}

	.wenan_right {
		width: 600rpx;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		align-items: flex-start;
	}

	.wenan_right_top {
		height: 80rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.wenan_right_top_left {
		width: 450rpx;
		height: 80rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: flex-start;
		overflow: hidden;
	}

	.wenan_nickname {
		height: 30rpx;
		line-height: 30rpx;
		color: #000;
		font-size: 30rpx;
		margin-bottom: 15rpx;
		white-space: nowrap;
		text-overflow: ellipsis;
		font-weight: 600;
	}

	.wenan_date {
		height: 26rpx;
		line-height: 26rpx;
		color: rgb(138, 138, 138);
		font-size: 26rpx;
	}

	.wenan_right_top_right {
		width: 150rpx;
		height: 80rpx;
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
		align-items: center;
		white-space: nowrap;
	}

	.wenan_right_top_right image {
		width: 30rpx;
		height: 30rpx;
		margin-right: 10rpx;
	}

	.wenan_right_top_right view {
		height: 30rpx;
		line-height: 30rpx;
		color: rgb(104, 104, 104);
		letter-spacing: 2rpx;
		font-size: 26rpx;
	}

	.wenan_right_content {
		width: 610rpx;
		white-space: pre-wrap;
		color: black;
		line-height: 45rpx;
		font-size: 30rpx;
		letter-spacing: 2rpx;
		margin: 10rpx 0;
	}

	.img_view {
		width: 630rpx;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		flex-wrap: wrap;
	}

	.img_view image {
		width: 400rpx;
		border-radius: 10rpx;
	}

	.pics_view {
		width: 600rpx;
		display: flex;
		flex-direction: row;
		/* justify-content: space-between; */
		flex-wrap: wrap;
	}

	/* .pics_view::after{
	  content:'' ;
	  width: 40rpx;
	} */
	.pics_view .image1 {
		width: 400rpx;
		margin-bottom: 20rpx;
		border-radius: 10rpx;
	}

	.pics_view .image2 {
		width: 260rpx;
		height: 260rpx !important;
		margin-bottom: 20rpx;
		border-radius: 10rpx;
		margin-right: 20rpx;
	}

	.pics_view .image3 {
		width: 190rpx;
		height: 190rpx !important;
		margin-bottom: 1.2vw;
		border-radius: 10rpx;
		margin-right: 1.2vw;
	}

	.pics_view #video-intro {
		width: 550rpx;
	}

	.wenan_btns {
		width: 100%;
		height: 35rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		margin-top: 30rpx;
		margin-bottom: 25rpx;
	}

	.btns_item {
		width: 210rpx;
		height: 35rpx;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		position: relative;
	}

	.btn_share {
		width: 210rpx;
		height: 35rpx;
		position: absolute;
	}

	.btns_item image {
		width: 40rpx;
		height: 40rpx;
		margin-right: 13rpx;
	}

	.btns_item view {
		font-size: 28rpx;
		color: rgb(127, 127, 127);
	}

	.btn_tougao {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50rpx;
		overflow: hidden;
		position: fixed;
		right: 30rpx;
		bottom: 50rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		z-index: 999;
		background-color: rgb(76, 76, 76);
	}

	.btn_tougao image {
		width: 27rpx;
		height: 27rpx;
		margin-bottom: 15rpx;
	}

	.btn_tougao view {
		color: white;
		font-size: 23rpx;
		height: 23rpx;
		line-height: 23rpx;
	}

	.btn_gongxian {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50rpx;
		overflow: hidden;
		position: fixed;
		right: 30rpx;
		bottom: 170rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		z-index: 999;
		background-color: rgb(254, 152, 5);
	}

	.btn_gongxian image {
		width: 35rpx;
		height: 35rpx;
		margin-bottom: 10rpx;
	}

	.btn_gongxian view {
		color: white;
		font-size: 23rpx;
		height: 23rpx;
		line-height: 23rpx;
	}

	.select_back_view {
		width: 750rpx;
		height: 100%;
		position: absolute;
		left: 0rpx;
		top: 379rpx;
		background-color: rgba(0, 0, 0, 0.3);
		z-index: 98;
	}

	.select_view {
		width: 750rpx;
		position: relative;
		margin-top: 30rpx;
		z-index: 99;
		background-color: white;
	}

	.select_view_guding {
		position: fixed;
		top: 0rpx;
		left: 0rpx;
		margin-top: 0rpx;
	}

	.select_title {
		width: 700rpx;
		/* height: 60rpx; */
		position: relative;
		display: flex;
		/* flex-direction: row; */
		flex-wrap: wrap;
		justify-content: flex-start;
		align-items: center;
		padding-bottom: 20rpx;
		left: 50%;
		transform: translateX(-50%);
	}

	.select_title_item {
		/* width: 125rpx; */
		padding: 0 17rpx;
		height: 58rpx;
		line-height: 58rpx;
		text-align: center;
		border-radius: 10rpx;
		/* background-color: white;
	  color: rgb(111, 111, 111); */
		background-color: rgb(239, 239, 239);
		color: rgba(96, 96, 96, 1);
		font-size: 26rpx;
		margin: 12rpx 10rpx 12rpx 0;
	}

	.select_title_item_on {
		background-color: #0083fd;
		color: #fff;
	}

	.select_fenlei {
		width: 142rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		position: absolute;
		right: 0rpx;
		background-color: rgb(239, 239, 239);
		color: rgb(114, 114, 114);
		font-size: 30rpx;
		border-radius: 10rpx;
	}

	.select_fenlei_body {
		width: 700rpx;
		position: relative;
		left: 20rpx;
	}

	.select_fenlei_body_top {
		width: 730rpx;
		position: relative;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		flex-wrap: wrap;
	}

	.select_fenlei_item {
		width: 122rpx;
		text-align: center;
		height: 50rpx;
		line-height: 50rpx;
		font-size: 26rpx;
		border-radius: 10rpx;
		border: 2rpx solid rgb(199, 199, 199);
		color: #000000;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
	}

	.select_fenlei_item_on {
		background-color: #0083fd;
		color: #fff;
	}

	.select_fenlei_btns {
		width: 750rpx;
		height: 90rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		position: relative;
		left: -20rpx;
	}

	.select_fenlei_btns_left {
		width: 373rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		border-top: 2rpx solid rgba(199, 199, 199, 0.2);
	}

	.select_fenlei_btns_right {
		width: 375rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		color: #fff;
		background-color: #0083fd;
	}
</style>